package ch10oopexer1;
/*老师有年龄，学校，姓名的属性，有上课和自我介绍的方法，如果年龄少于22岁，抛出异常。*/
public class Teacher {
    private String name;
    private int age;
    private String school;

    public Teacher() {
    }

    public Teacher(String name, int age, String school) {
        this.name = name;
        this.age = age;
        this.school = school;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age)throws Exception {
        if(age<22){
            throw new Exception("年龄小于22岁呀");
        }
        this.age = age;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public void calss(){
        System.out.println(name+"老师上课！");
    }
    public void show(){
        System.out.println("姓名："+name+" ,年龄："+age+" ,学校："+school);
        calss();
    }
}
